package cn.com.jonpad.api.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Jon Chan
 * @date 2018/9/10 15:09
 */
@Accessors(chain = true)
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable {

	private static final String CODE = "code";
	private static final String MSG = "msg";
	private static final long serialVersionUID = 2633283546876721434L;

	private Integer code=200;
	private String msg="操作成功";
	private String description;
	private T data;

	@JsonIgnore
	private Map<String,Object> exend;
	public Result() {
		exend = new HashMap<>();
	}
	public static Result failure(int code, String msg) {
		Result result = new Result();
		result.setCode(code);
		result.setMsg(msg);
		return result;
	}

	public static Result ok(String msg) {
		Result result = new Result();
		result.put("msg", msg);
		return result;
	}
	public static Result ok(Object data) {
		Result result = new Result();
		result.setData(data);
		return result;
	}

	public static Result ok(Map<String, Object> map) {
		Result result = new Result();
		result.exend.putAll(map);
		return result;
	}

	public static Result ok() {
		return new Result();
	}

	public Result put(String key, Object value) {
		exend.put(key, value);
		return this;
	}
}
